﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 职工端
{
    public partial class denglu : Form
    {
        public static string strcon= "server=localhost;database=KHDGDB;uid=sa;pwd=hao123";
        public denglu()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            个人信息修改.account = textBox1.Text;//获取职工账号
            string Waccount = this.textBox1.Text;
            string Wpassword = this.textBox2.Text;
            if (Waccount.Equals("") || Wpassword.Equals(""))
            {
                MessageBox.Show("用户名或密码不能为空！");
            }
            else
            {

                try
                {
                    SqlConnection con = new SqlConnection(strcon);
                    con.Open();
                    string sqlSel = "select * from Worker where Waccount = '" + Waccount + "'  and Wpassword =  '" + Wpassword + "'";
                    SqlCommand com = new SqlCommand(sqlSel, con);
                    SqlDataReader sdr = com.ExecuteReader();
                    string a = "";
                    string b = "";
                    while (sdr.Read())
                    {
                        a = sdr["Waccount"].ToString();
                        b = sdr["Wpassword"].ToString();

                    }
                    if (a.Equals(textBox1.Text) && b.Equals(textBox2.Text))
                    {
                        MessageBox.Show("登录成功！");
                        /*this.DialogResult = DialogResult.OK;      
                          this.Dispose();
                          this.Close();*/
                        MainForm next = new MainForm();//创建将要打开的窗体对象
                        next.Show(); // 打开新窗体--Show非模式对话框--ShowDialog模式对话框
                        this.Hide(); // this.Close()关闭当前窗体,因为登录是主窗体所以不能关闭


                    }            //用户名和密码验证错误，提示错误。

                    else
                    {
                        MessageBox.Show("用户名或密码错误！");
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString() + "失败");
                }
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            注册 next = new 注册();//创建将要打开的窗体对象
            next.Show(); // 打开新窗体--Show非模式对话框--ShowDialog模式对话框
            this.Hide(); // this.Close()关闭当前窗体,因为登录是主窗体所以不能关闭
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();
        }
    }
}
            
        
    

